import { login } from '@/api/login' //登录接口

import {getToken,setToken,removeToken} from "../../utils/auth";

const user = {
  state:{
    token:getToken()
  },
  mutations:{
    SET_TOKEN:(state,token) =>{
      state.token=token
    }
  },
  actions:{
    //登录
    Login({commit},userInfo){
      // dosomething
      return new Promise((resolve, reject) => {
        login(userInfo).then(res=>{
          setToken('already get it')
          commit('SET_TOKEN','already get it')
          resolve()
          //resolve(res)  //or get it pass
        }).catch(err=>{
          console.log(err)
          reject()
        })
      })
    },
    Logout({commit}){
      // dosomething
      return new Promise((resolve, reject) => {

      })
    }
  }
}

export default user
